import store from './vuex/index'
import router from './routers/index'
// 全局错误处理，全局loading
import { mapState, mapMutations } from './vuex/index.js'

export default function (request, next) {
    store.commit('LOADING_TOGGLE',true);
    request.headers.set('Authorization', window.localStorage.getItem('_t'));
    next((res) => {
      setTimeout(function (){
        store.commit('LOADING_TOGGLE',false);
      }, 200);
      if (res.body.messageCode != null && res.body.messageCode === 1000) {
        store.dispatch('toastToggle', {info: "登录已过期，请重新登录", isToasting: true, time: 1200, icon: 2});
        router.push({name:'login'});
      }
    })
}
